﻿Public Class Frm_jalassat
    Public ijr As ijraa

    Dim ds As New DataSet1
    Dim row As DataRow

    Public Sub remplir_List_ijra2()
        Dim str As String = ""
        If Comb_ijra2.Text <> "جميع الإجراءات" Then
            str = " and Ijraa='" & Comb_ijra2.Text & "'"
        End If
        Partager.list_crystal.Clear()
        Dim cmd As New SqlClient.SqlCommand("select * from  Ijraa where Date_Ijraa between '" & Format(Date_min.Value.Date, "yyyy/MM/dd") & "' and '" & Format(Date_illa.Value.Date, "yyyy/MM/dd") & "'" & str & " order by Date_Ijraa", Partager.con)
        Partager.open()
        Partager.dr = cmd.ExecuteReader
        If Partager.dr.HasRows Then
            While Partager.dr.Read
                Dim khab As New ijraa(Partager.dr("id"), Partager.dr("Id_Dossier"), Partager.dr("Ijraa"), Partager.dr("salle"), Partager.dr("Date_Ijraa"), Partager.dr("Responsable_Ijraa"), Partager.dr("Serveur_Ijraa"), Partager.dr("Jour"), Partager.dr("Heur"), Partager.dr("Cause"), Partager.dr("Remarque"))
                Partager.list_crystal.Add(khab)
            End While
        End If
        Partager.close()
    End Sub

    'Public Sub Remplir()
    '    ds.Tables("Jalassat").Rows.Clear()
    '    remplir_List_ijra2()
    '    '--------------------------------------

    '    Partager.moi.remplir_List_client()
    '    Partager.moi.remplir_List_enemi()
    '    Partager.moi.remplir_List_info_fichier()
    '    For Each khib As ijraa In Partager.list_crystal
    '        row = ds.Tables("Jalassat").NewRow()
    '        row("Jour") = khib.Jour
    '        row("Salle") = khib.Salle
    '        row("Cause") = khib.Cause
    '        row("Date") = Format(khib.Date_ijraa, "yyyy/MM/dd")
    '        row("Ijra2") = khib.Ijraa
    '        row("Heur") = khib.Heure
    '        For Each dos As Dossier In Partager.moi.List_info_fichier
    '            If khib.Id_Dossier = dos.id Then
    '                row("Tribunal") = dos.Tribunal
    '                row("Num_Dossier") = dos.Num
    '                '-----------------------------------------
    '                dos.remplir_List_mo9arir()
    '                For Each mo9 As M9arir In dos.List_mo9arir
    '                    If mo9.actif = True Then
    '                        row("Mo9arir") = mo9.Nom
    '                        Exit For
    '                    End If
    '                Next
    '                '-----------------------------------------
    '                dos.remplir_List_client()
    '                Dim str As String = ""
    '                Dim strr As String = ""
    '                Dim cont As Integer = 0
    '                For Each doss_clt As Dossiers_Clients In dos.List_client
    '                    For Each clt As Client In Partager.moi.List_client
    '                        If doss_clt.Id_Clients = clt.Id Then
    '                            cont += 1
    '                            If clt.Type = "ذاتي" Then
    '                                str = clt.Nom & "  " & clt.Prenom
    '                            ElseIf clt.Type = "معنوي" Then
    '                                str = clt.Nom_ent
    '                            End If
    '                            If cont > 1 Then
    '                                strr = str & " / " & strr
    '                            Else
    '                                strr = str
    '                            End If
    '                        End If
    '                    Next
    '                Next
    '                row("Client") = strr
    '                '---------------------------------------
    '                Exit For
    '            End If
    '        Next
    '        ds.Tables("Jalassat").Rows.Add(row)

    '    Next

    '    Dim dv As DataView = New DataView(ds.Tables("Jalassat"))
    '    dv.Sort = "Mo9arir ASC"

    '    Dim crys As New Crys_Jalassat
    '    crys.SetDataSource(dv)

    '    crys.SetParameterValue("Title", Date_illa.Value.Date & "  ورقـــــــــة  الجلســــــــات  من " & Date_min.Value.Date & "  إلى  ")

    '    Crystal_jalassat.ReportSource = crys
    '    Crystal_jalassat.Refresh()
    '    '---------------------------------

    'End Sub

    Public Sub Remplir()
        Dim dateEtJour As String = ""
        ds.Tables("Jalassat").Rows.Clear()
        remplir_List_ijra2()
        '--------------------------------------

        Partager.moi.remplir_List_client()
        Partager.moi.remplir_List_enemi()
        Partager.moi.remplir_List_info_fichier()
        For Each khib As ijraa In Partager.list_crystal
            row = ds.Tables("Jalassat").NewRow()
            'dateEtJour = Format(khib.Date_ijraa, "dd/MM/yyyy") & " " & khib.Jour
            row("Date") = Format(khib.Date_ijraa, "dd/MM/yyyy")
            row("jour") = khib.Jour
            row("Salle") = khib.Salle
            row("Cause") = khib.Cause
            row("Ijra2") = khib.Ijraa
            row("Heur") = khib.Heure

            For Each dos As Dossier In Partager.moi.List_info_fichier
                If khib.Id_Dossier = dos.id Then
                    row("Tribunal") = dos.Tribunal
                    row("Num_Dossier") = dos.Num
                    '-----------------------------------------
                    dos.remplir_List_mo9arir()
                    For Each mo9 As M9arir In dos.List_mo9arir
                        If mo9.actif = True Then
                            row("Mo9arir") = mo9.Nom
                            Exit For
                        End If
                    Next
                    '-----------------------------------------
                    Dim str As String = ""
                    Dim strr As String = ""
                    Dim cont As Integer = 0
                    Dim cmd As New SqlClient.SqlCommand("select idAdv,idClt from refClt,refAdv" & _
                                " where refClt.idRef=refAdv.idRef and refClt.idRef=" & dos.Ref, Partager.con)
                    Partager.open()
                    Partager.dr = cmd.ExecuteReader
                    If Partager.dr.HasRows Then
                        Partager.dr.Read()
                        For Each clt As Client In Partager.moi.List_client
                            If Partager.dr("idClt") = clt.Id Then
                                cont += 1
                                If clt.Type = "ذاتي" Then
                                    str = clt.Nom & "  " & clt.Prenom
                                ElseIf clt.Type = "معنوي" Then
                                    str = clt.Nom_ent
                                End If
                                If cont > 1 Then
                                    strr = str & " / " & strr
                                Else
                                    strr = str
                                End If
                            End If
                        Next
                        row("Client") = strr
                        '-----------------------------------------
                        str = ""
                        strr = ""
                        cont = 0
                        For Each enm As Enemie In Partager.moi.List_enemi
                            If Partager.dr("idAdv") = enm.Id Then
                                cont += 1
                                If enm.Type = "ذاتي" Then
                                    str = enm.Nom & "  " & enm.Prenom
                                ElseIf enm.Type = "معنوي" Then
                                    str = enm.Nom_ent
                                End If
                                If cont > 1 Then
                                    strr = str & " / " & strr
                                Else
                                    strr = str
                                End If
                            End If
                        Next
                    End If
                    Partager.dr.Close()
                    Partager.close()
                    row("Adversaire") = strr
                    '-----------------------------------------
                End If
            Next
            ds.Tables("Jalassat").Rows.Add(row)

        Next

        Dim dv As DataView = New DataView(ds.Tables("Jalassat"))

        Dim crys As New CrystJalassat
        crys.SetDataSource(dv)

        crys.SetParameterValue("titre", Date_illa.Value.Date & "  ورقـــــــــة  الجلســــــــات  من " & Date_min.Value.Date & "  إلى  ")

        Crystal_jalassat.ReportSource = crys
        Crystal_jalassat.Refresh()
        '---------------------------------

    End Sub

    Private Sub Frm_jalassat_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Comb_ijra2.SelectedIndex = 0
    End Sub

    Private Sub Btn_Rech_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Btn_Rech.Click
        Remplir()
    End Sub
End Class